package com.maker.LMMS.init;


import com.blade.Blade;
import com.blade.Environment;
import com.blade.ioc.annotation.Bean;
import com.blade.jdbc.Base;
import com.blade.loader.BladeLoader;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import java.util.Map;
import java.util.Properties;

/**
 * @author : zimu
 * @Date: 2018/7/31 14:19
 * @description : 初始化数据库连接
 */

//@Bean
//public class DaoBean implements BladeLoader {

//    @Override
//    public void load(Blade blade) {
//        HikariConfig config = new HikariConfig();
//        config.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/lmms");
//        config.setUsername("root");
//        config.setPassword("1");
//        config.addDataSourceProperty("cachePrepStmts", "true");
//        config.addDataSourceProperty("prepStmtCacheSize", "250");
//        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
//        config.setConnectionTestQuery("set names utf8mb4");
//        HikariDataSource ds = new HikariDataSource(config);
//        Base.open(ds);
//    }
//}

@Bean
public class DaoBean implements BladeLoader {
    @Override
    public void load(Blade blade) {
        Environment ev = blade.environment();
        Map<String,Object> hikari = ev.getPrefix("hikari");
        Properties ps = new Properties();
        ps.putAll(hikari);

        HikariDataSource dataSource = new HikariDataSource(new HikariConfig(ps));
        Base.open(dataSource);
    }
}

